import javax.swing.text.html.HTMLDocument;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-11-29
 * 19:47
 */
class  ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
        this.val = val;
    }
}
 class Test {

    public static void main(String[] args) {
        ListNode p1=new ListNode(1);
        p1.next=new ListNode(3);
        p1.next.next=new ListNode(5);

        ListNode p2=new ListNode(2);
        p2.next=new ListNode(4);
        p2.next.next=new ListNode(6);
        Merge(p1,p2);
    }
    public static ListNode Merge(ListNode pHead1, ListNode pHead2) {
        // write code here
         ListNode head=new ListNode(-1);
        ListNode cur=head;
        while(pHead1!=null&&pHead2!=null){
            if(pHead1.val<pHead2.val){
                cur.next=pHead1;
                cur=cur.next;
                pHead1=pHead1.next;
            }else{
                cur.next=pHead2;
                cur=cur.next;
                pHead2=pHead2.next;
            }
        }
        if(pHead1!=null){
            cur.next=pHead1;
        }else if(pHead2!=null){
            cur.next=pHead2;
        }
        return head.next;
    }
}
